package com.guoguo.controller;

import com.alibaba.fastjson.JSONObject;
import com.guoguo.base.BaseController;
import com.guoguo.base.PageBean;
import com.guoguo.entity.Orders;
import com.guoguo.entity.vo.OrdersVO;
import com.guoguo.service.OrderService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by KLSD on 2017/9/29.
 */
@Controller
@RequestMapping("/view")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;

    //查询
    @RequestMapping(value = "/order", method = RequestMethod.GET)
    public ModelAndView order(@RequestParam int pageNumber, @RequestParam int pageSize) {
        Map<String, Object> data = new HashMap<>();
        PageBean<OrdersVO> ordersVO = orderService.selectOrdersList(pageNumber, pageSize);
        data.put("ordersList", ordersVO);
        return returnView("/order", data);

    }
    //编辑
    @ResponseBody
    @RequestMapping(value="/getOrderNo",method=RequestMethod.POST)
    public JSONObject getOrder(String orderNo){

        JSONObject ordersno=new JSONObject();
        Orders order=orderService.selectByPrimaryKey(orderNo);
        ordersno.put("orders",order);
        return  returnResult(200,ordersno,"");


    }
    @RequestMapping(value="/updateOrders",method=RequestMethod.GET)
    public JSONObject updateOrders(Orders orders){
        Map<String, Object> data = new HashedMap();
        int order=orderService.updateByPrimaryKeySelective(orders);
        data.put("orders",order);
        return returnResult(200,data,"");

    }



}
